<template>
  <div @click="toLive">
    <div class="loading-box" v-if="isLoading">
      <loading></loading>
    </div>
    <div>
      <div class="tabs"></div>
      <div class="list">
        <swiper :options="option">
          <swiper-slide
            v-for="(item, index) in items"
            :key="index">
            <list-item :id="item.id" :key="item.id"></list-item>
          </swiper-slide>
        </swiper>
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import ListItem from './listItem'
export default {
  name: 'list',
  computed: {
    ...mapGetters({
      info: 'global/info'
    })
  },
  components: {
    ListItem
  },
  created () {
    if (Object.keys(this.$route.query).length === 3) {
      let { source_app, idfa } = this.$route.query
      let param = {
        source_app,
        idfa
      }
      if (this.$route.query.user_id !== '0') {
        param['user_id'] = this.$route.query.user_id
      }
      this.$store.dispatch('global/setInfo', param)
    }
    this.isLoading = true
    this.$api.get('ads/index2').then((res) => {
      this.items = res.data.ad_item_list
      this.isLoading = false
    })
  },
  data () {
    return {
      isLoading: false,
      items: [],
      option: {
        pagination: '.tabs',
        paginationClickable: true,
        mousewheelControl: true,
        observeParents: true,
        paginationBulletRender: (swiper, index, className) => {
          if (this.items.length < 1) return
          return '<span class="' + className + '">' + this.items[index].item_name + '</span>'
        }
      }
    }
  },
  methods: {
    toLive () {
      window.ga && window.ga('send', 'event', this.appname, '点击', '活人')
    }
  }
}
</script>
<style lang="scss">
.ads-list {
  display: flex;
  flex-wrap: wrap;
  padding: 5px;
}
.list {
  .swiper-container {
    min-height: calc(100vh - 100px);
    height: auto;
  }
}
.tabs {
  display: flex;
  width: 100vw;
  .swiper-pagination-bullet {
    display: flex;
    flex-grow: 1;
    flex-basis: 0;
    flex-shrink: 0;
    border-radius: 0;
    height: 40px;
    color: white;
    justify-content: center;
    align-items: center;
    opacity: 1;
    background: white;
    color: gray;
    &.swiper-pagination-bullet-active {
      background: #0f95e2;
      color: white;
    }
  }
}
</style>


